package com.exceptionhandler.service.crawl;

import java.util.ArrayList;
import java.util.List;

import org.neocrawler.entity.WebContent;

import data.processor.URLFilter;

public class JGraphForumCrawler extends ExceptionCrawler implements
		IExceptionCrawler {
	// ========== Required!!!! ========== //
	private static final String PROJECT_NAME = "JGraphForum";
	private static final String PARSER_CLASS_NAME = JGraphForumCrawler.class
			.getName();
	private static String SEED_URLS = "http://forum.jgraph.com/";

	// ========== Optional ========== //
	private static final String STORE_PATH = BASE_STORE_PATH + PROJECT_NAME
			+ "\\";
	private static final boolean USE_PROXY_OR_NOT = true;
	private static final int THREAD_NUM = 4;
	private static final String PROXY_URL = "192.168.4.31";
	private static final int PROXY_PORT = 3128;

	public JGraphForumCrawler() {
		super(PROJECT_NAME, SEED_URLS, STORE_PATH, PARSER_CLASS_NAME,
				THREAD_NUM, USE_PROXY_OR_NOT, PROXY_URL, PROXY_PORT);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.neocrawler.parser.IParser#getInitialSeeds()
	 */
	@Override
	public List<WebContent> getInitialSeeds() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.neocrawler.parser.IParser#parse(org.neocrawler.entity.WebContent,
	 * java.lang.String)
	 */
	@Override
	public List<WebContent> parse(WebContent webContent, String webPage) {
		List<WebContent> webContents = URLFilter
				.getWebContentList_JGRAPHFORUM(webPage);
		System.err.println("webContents null?" + webContents == null);
		if (webContents == null) {
			return null;
		} else {
			System.err.println(webContents.size());
			List<WebContent> results = new ArrayList<WebContent>();
			for (int i = 0; i < webContents.size(); i++) {
				try {
					WebContent w = webContents.get(i);
					w.setParentUrl(webContent.getUrl());
					w.setParentUuid(webContent.getUuid());
					w.setReserve02(PROJECT_NAME);
					results.add(w);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return results;
		}
	}

	/**
	 * Description:
	 * 
	 * @param args
	 *            void
	 */
	public static void main(String[] args) {
		JGraphForumCrawler crawler = new JGraphForumCrawler();
		crawler.start();
	}
}
